home *** CD-ROM | disk | FTP | other *** search
- // Pine 4.xx, ipop3d 4.xx and other /tmp-lock based mail stuff.
-
- #include <sys/file.h>
- #include <sys/stat.h>
- #include <unistd.h>
-
- main(int argc,char* argv[])
- {
- int i,a=0;
- char s[100];
- struct stat x;
- if (!argv[1]) exit(printf("Usage: %s account_name\n",argv[0]));
- sprintf(s,"/var/spool/mail/%s",argv[1]);
- if (stat(s,&x)) exit(printf("Mailbox (%s) not found.\n",s));
- sprintf(s,"/tmp/.%x.%x",(int)x.st_dev,(int)x.st_ino);
- fchmod(i=open(s,O_RDWR|O_CREAT,0600),0666);
- while (1)
- {
- lseek(i,0,0);
- write(i,"-1",2);
- ftruncate(i,2);
- fsync(i);
- if (!a++) if (!flock(i,LOCK_EX)) printf("Got lock on %s.\n",s);
- else printf("File %s already locked, wait...\n",s);
- sleep(1);
- }
- }
- /* www.hack.co.za [2000]*/